//文章评论

import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn, UpdateDateColumn, CreateDateColumn, OneToMany, ManyToMany, JoinTable } from 'typeorm';
import { UserAccount } from 'src/user_account/entities/user_account.entity'
import { Article } from './article.entity';
@Entity({ name: 'article_comment' })
export class ArticleComment {
    @PrimaryGeneratedColumn()
    id: number

    @Column()
    author: string

    @Column({ type: 'text', nullable: true, comment: '评论内容' })
    content: string

    @CreateDateColumn({ type: "timestamp", name: 'create_time' })
    createTime: Date;

    @ManyToOne(type => Article, article => article.comment,{onDelete:'CASCADE'})
    @JoinColumn()
    article: Article

    @ManyToOne(type => UserAccount, UserAccount => UserAccount.comment)
    @JoinColumn()
    userAccount: UserAccount

    @OneToMany(type => ArticleComment, replies => replies.parent)
    replies: ArticleComment[]

    @ManyToOne(type => ArticleComment, parent => parent.replies, { nullable: true, onDelete: 'CASCADE' })
    parent: ArticleComment


    @ManyToMany(() => UserAccount, likers => likers.commentLikes)
    @JoinTable({
        name:'user_like_comment',
        joinColumn: { name: 'comment_id', referencedColumnName: 'id' },
        inverseJoinColumn: { name: 'user_id', referencedColumnName: 'id' },
    })
    likers: UserAccount[]
}


